package com.swn.cm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swn.common.util.DbHelper;
import com.swn.common.util.PageListData;
import com.swn.common.util.StringUtil;

@Service("StudentsService")
public class StudentsService {
	@Autowired
	DbHelper dbHelper ;
	
	/**
	 * 查询学生信息列表
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	public List<Map<String, Object>> queryStudentsList(PageListData page,Map<String, Object> paramMap) throws Exception{
 		StringBuffer sql = new StringBuffer();
		sql.append("select " + "s.id,s.stuname,s.stuage,s.stusex,s.createtime,s.classname,s.classcode");
		sql.append("  from shop_dong_stu s where 1=1 ");
        String name = (String) paramMap.get("name");
		
		if (StringUtil.isNotEmpty(name)){
			sql.append(" and s.stuname like :name");
			paramMap.put("name", "%" + name + "%");
		}
		
		//sql.append(" limit "+page.getStart()+" , "+ page.getPageSize());
		
        //return dbHelper.queryForList(sql.toString(), paramMap);	
		return dbHelper.queryPageMapList(page, sql.toString(), paramMap);
	}
	
	
	/**
	 * 根据ID 编号，查询单条学生信息
	 * @param id
	 * @return
	 */
	public Map<String, Object> queryStudentById(Long id){
		Map <String ,Object> keyMap = new HashMap<>();
		keyMap.put("id", id);
		return dbHelper.queryMapById(keyMap, "shop_dong_stu");	
		
	}

	/**
	 * 添加学生信息
	 * @param paramMap
	 * @return
	 */
	public int addStudents(Map<String, Object> paramMap){
		
		return dbHelper.saveMap(paramMap, "shop_dong_stu");
	}
	
	/**
	 * 修改学生信息
	 * @param paramMap
	 * @return
	 */
	public int updateStudent(Map<String,Object> paramMap){
		return dbHelper.updateMap(paramMap, "shop_dong_stu");
	}
	
	
	/**
	 * 根据ID编号   删除学生信息
	 */
	public int deleteStudent(Long id){
		Map<String ,Object> keyMap = new HashMap<>();
		keyMap.put("id", id);
		return dbHelper.delete(keyMap, "shop_dong_stu");
	}
	
	/**
	  * 查询所有的班级
	  * 
	  * @return List<Map<String,Object>>
	  *
	  * @Author dongliang
	  * @Date 2018年8月4日 上午11:02:06 
	  * @Note <这里是方法的备注>
	  * 修改日期  修改人  修改内容
	  */
	public List<Map<String, Object>> queryClassList(){
		StringBuilder sql = new StringBuilder();
		sql.append("  select ").append("s.id,s.name ,s.code");
		sql.append("  from shop_cm_class s ");
		Map<String,Object> paramMap = null ;
		
		return dbHelper.queryForList(sql.toString(), paramMap);
		
	}
}
